<?PHP
#
# author: Cody Sorgenfrey with Jason Sanchez
# (c) 2012 Casa De Bendicion
#

putenv("TZ=US/Pacific");

//Is there a table named $table in this database
function tableExists ($table, $db) { 
  $tables = mysql_list_tables ($db); 
  while (list ($temp) = mysql_fetch_array ($tables)) {
//printf("test2 %s\n", $temp);
    if ($temp == $table) {
      return TRUE;
    }
  }
  return FALSE;
}

function connectSelectTest ($table) {
  global $hostname, $username, $password, $database;

  //Connected to the database
  $con = mysql_connect($hostname,$username,$password);
  if (!$con)
  {
    printf("host:%s user:%s data:%s\n", $hostname, $username, $database);
    die('Could not connect: ' . mysql_error());
  }

  //Select the database
  $db_selected = mysql_select_db($database, $con);
  if (!$db_selected)
  {
    die ("Can't use $database : " . mysql_error());
  }

  //Does table exist
  if (!tableExists($table, $database)) {
    die("Query failed " . mysql_error());
  }
}

?>